package test.org.jdk.test2;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;

/**
 * Created by lcx on 2017/6/2.
 */
public class SubjectInvocationHandler implements InvocationHandler {

    private Object delegate;

    public SubjectInvocationHandler(Object bookService){
        this.delegate = bookService;
    }

    @Override
    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
        prepareMoneyForBuyBook();
        Object obj = method.invoke(delegate, args);
        readBookAfterBuy();
        return obj;
    }

    private void prepareMoneyForBuyBook(){
        System.out.println("为买本准备好钱...");
    }

    private void readBookAfterBuy(){
        System.out.println("终于可以看自己喜欢的书了...");
    }
}
